<template>
  <!-- 街机-扫雷详情 -->
  <el-dialog v-if="props.show" :modelValue="props.show" custom-class="detailData" :title=" selectToLabel(indexStore.gameArray, props.checkedItem.game_id)+' 详情'" 
  :close-on-click-modal="false" :close-on-press-escape="false" @close="onHideDetails">
    <div class="border-box">
      <template v-for="(item, index) in data.filArr" :key="index">
        <div class="flex list">
          <div class="width20">
            {{ item.label }}
          </div>
          <div class=" ">
            <span v-if="item.key == 'win'" :class="colorClass(item.value)">
              {{ item.value }}</span>
            <span v-else>{{ item.value }}</span>
          </div>
        </div>
      </template>
    </div>
  </el-dialog>
</template>

<script setup lang="ts">
import { ref, reactive, toRefs, watch, onMounted } from 'vue'
import { getGameReportDetails } from '@/api/player'
import { setTimestampTime } from '@/utils/time'
import { BigWan, BigTofixedTwo } from '@/utils/math'
import { selectToLabel, colorClass } from '@/utils/index'
import { useStore } from '@/stores/index'
// import { useI18n } from 'vue-i18n'
// const { t } = useI18n()
const indexStore = useStore()

const props = defineProps({
  show: {
    type: Boolean,
    default: () => {
      return false
    }
  },
  checkedItem: {
    type: Object,
    default: () => {
      return {}
    }
  }
})

const data = reactive({
  filArr: [] as any[],
})

watch(
  () => [props.checkedItem,props.show],
  async (value) => {
    if (value[0] && value[1]) {
      gameDetails()
    }
  },
)

// 详情
const gameDetails = async() => {
  let query = {
    log_details_id: props.checkedItem.log_details_id,
    game_id: props.checkedItem.game_id
  }
  let res = {} as any
  if(!props.checkedItem.log_json){
    res = await getGameReportDetails(query)
  }else{
    res = JSON.parse(props.checkedItem.log_json)
  }
  console.log('街机详情',res);
  data.filArr = [
    { label: '游戏', value: selectToLabel(indexStore.gameArray, props.checkedItem.game_id), key: 'game_id' },
    { label: '牌局编号', value: props.checkedItem.round_id_str, key: 'round_id_str' },
    { label: '时间', value: setTimestampTime(props.checkedItem.save_time_stamp), key: 'created_time_stamp' },
    { label: '本局下注', value: BigWan(props.checkedItem.bet), key: 'bet' },
    { label: '当局选择雷数', value: res.field_size, key: 'field_size' },
    { label: '游戏步数', value: res.cash_out > 0 ? res.select_num : 0, key: 'select_num' },
    { label: '中雷步数', value: res.cash_out > 0 ? 0 : res.select_num, key: 'cash_out' },
    { label: '是否为自动', value: res.is_auto == 1 ? '是' : '否', key: 'is_auto' },
    { label: '中奖倍数', value: BigTofixedTwo(res.x), key: 'x' },
    { label: '结果', value: BigWan(props.checkedItem.win - props.checkedItem.bet), key: 'win' },
  ]
}

// 重置
const emit = defineEmits(['onHideDetails'])
const onHideDetails = () => {
  emit('onHideDetails', false)
}
</script>
<style scoped lang="scss">
.border-box {
  padding-bottom: 40px;
  font-size: 14px;
  color: var(--text);
}

.fily {
  display: flex;
  flex-wrap: wrap;
  width: 100%;

  .fily-list {
    width: 50%;
  }
}

.flight {
  width: 100%;
}

.list {
  font-weight: bold;
  height: 36px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--el-border-color-lighter);
}
</style>